<template>
  <div class="register-container">
       <!-- 自定义顶部栏 -->
  <div class="custom-title-bar">
    <div class="title-left">
      <img class="title-logo" src="@/assets/icons/tray-1.png" alt="logo" />
      <span class="title-text">SIX</span>
    </div>
    <div class="window-controls">
      <el-icon @click="minimizeWindow"><Minus /></el-icon>
      <el-icon @click="toggleMaximizeWindow"><FullScreen /></el-icon>
      <el-icon @click="closeWindow"><Close /></el-icon>
    </div>
  </div>

    <div class="register-card">
      <h2 class="title">注册账号</h2>

      <el-form :model="form" :rules="rules" ref="formRef" label-position="top">
        <el-form-item prop="username">
          <el-input
            v-model="form.username"
            placeholder="请输入昵称"
            prefix-icon="el-icon-user"
            size="large"
          />
        </el-form-item>

        <el-form-item prop="password">
          <el-input
            v-model="form.password"
            placeholder="请输入密码"
            prefix-icon="el-icon-lock"
            show-password
            size="large"
          />
        </el-form-item>
      </el-form>

      <div class="button-group">
        <el-button type="primary" @click="register" round size="large" class="register-btn">注册</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue';
import request from '@/axios/index.js'
import { Minus, Close,FullScreen  } from '@element-plus/icons-vue';
const formRef = ref(null);
const form = reactive({
  username: '',
  password: '',
});

let isMaximized = false;

//最大化窗口
const toggleMaximizeWindow = () => {
  window.electronAPI?.ipcRenderer?.send('toggle-maximize');
  isMaximized = !isMaximized;
};

const rules = {
  username: [
    { required: true, message: '请输入昵称', trigger: 'blur' },
    { min: 2, message: '昵称至少2个字符', trigger: 'blur' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 6, message: '密码至少6位', trigger: 'blur' },
  ],
};

const register = () => {
  formRef.value.validate((valid) => {
    if (!valid) return;

    // 注册逻辑写这里
    console.log('要提交的数据：', form);
    request.post('/user/register',form).then((res) => {
      console.dir('注册成功',res);
    });
    
  });
};

// 自定义标题栏按钮操作
const minimizeWindow = () => {
  window.electronAPI?.ipcRenderer?.send('minimize-window');
};
const closeWindow = () => {
  window.electronAPI?.ipcRenderer?.send('close-window');
};
</script>

<style scoped>
.register-container {
  display: flex;
  height: 100vh;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #89f7fe, #66a6ff);
  font-family: "Segoe UI", sans-serif;
}

.custom-title-bar {
  height: 32px;
  -webkit-app-region: drag;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
}

.title-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-logo {
  width: 20px;
  height: 20px;
  -webkit-app-region: no-drag;
}

.title-text {
  font-weight: bold;
  font-size: 14px;
  -webkit-app-region: no-drag;
}

.window-controls {
  display: flex;
  gap: 12px;
  -webkit-app-region: no-drag;
}

.window-controls .el-icon {
  cursor: pointer;
  font-size: 18px;
  transition: color 0.2s;
}

.window-controls .el-icon:hover {
  color: #ff4d4f;
}

.register-card {
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(20px);
  padding: 2.5rem 3rem;
  border-radius: 20px;
  /* box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); */
  width: 340px;
  text-align: center;
}

.title {
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
  color: #fff;
}

.button-group {
  margin-top: 1.5rem;
}

.register-btn {
  width: 100%;
  background: linear-gradient(to right, #4facfe, #00f2fe);
  border: none;
  font-weight: bold;
  letter-spacing: 1px;
  font-size: 1.1rem;
}

.register-btn:hover {
  background: linear-gradient(to right, #00f2fe, #4facfe);
}
</style>
